package com.sscaipiao.android.activity.DongFangLiuJiaYi;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import com.sscaipiao.android.R;
import com.sscaipiao.android.activity.Base.NormalPayActivity;
import com.sscaipiao.android.activity.Base.RedBallDoubleArrayPayActivity;
import com.sscaipiao.android.activity.DaLeTou.DaLeTouActivity;
import com.sscaipiao.android.activity.HallActivity;
import com.sscaipiao.android.common.Constants;
import com.sscaipiao.android.utils.CaipiaoServiceHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class DongFangLiuJiaYiPayActivity extends RedBallDoubleArrayPayActivity{
	private final static String PayFunction = "betDLT.do";
	private final static String ZhuiHaoFunction = "betZHDLT.do";
	private final static Class ACITIVITY_MAIN = DongFangLiuJiaYiActivity.class;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitleText("东方6+1");
		setRandom(35, 5, 12, 1);
	}

	@Override
	public void onClick(View v) {
		super.onClick(v);
		if (R.id.add_by_hand == v.getId()) {
			//callMainAcitvity(DaLeTouActivity.class);
			finish();
		}
		if (R.id.add_by_auto == v.getId()) {
			setupOrderList();
		}
	    if ( R.id.pay_sure  == v.getId()) {
		    if (doPayPreCheck()) {
			    doPayWork();
		    }
	    }
	}

	private void doPayWork() {
		int zhuiHaoNum = Integer.parseInt(getPayAddDate());
		String retStr = CaipiaoServiceHelper.payLotteryRedballSingleRedball(this,user, date,
				//double_color_ball_pay_add_date.getText().toString(),
				getPayAddNumber(),
				totalMoney() / zhuiHaoNum + "",PayFunction);
		if (!retStr.startsWith(Constants.LOGIN_SUCCESS_CODE)){
			return;
		}
		String zhuihao = Constants.LOGIN_SUCCESS_CODE;
		// 追号 大于 一期 才调用追号接口
		if (zhuiHaoNum > 1) {
			zhuihao = CaipiaoServiceHelper.betZhuiHaoRedballSingleArray(this,user, date,getPayAddNumber(),
					totalMoney() * (zhuiHaoNum - 1) /zhuiHaoNum + "", null, null,ZhuiHaoFunction);
		}

		if (retStr.startsWith(Constants.LOGIN_SUCCESS_CODE) && zhuihao.startsWith(Constants.LOGIN_SUCCESS_CODE)) {
			Toast.makeText(this, "购买成功", Toast.LENGTH_SHORT).show();
			Intent intent = new Intent(this, HallActivity.class);
			Bundle b = new Bundle();
			b.putSerializable(Constants.USER, user);
			intent.putExtras(b);
			startActivity(intent);

		} else {
			Toast.makeText(this, retStr.split(Constants.STRING_SPLITE_COMPLEX)[1], Toast.LENGTH_SHORT).show();
			return;
		}
	}

}
